package tech.aistar.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.aistar.entity.Pet;
import tech.aistar.entity.Pettype;
import tech.aistar.mapper.PetMapper;
import tech.aistar.mapper.PettypeMapper;
import tech.aistar.service.IPetService;
import tech.aistar.util.IdWorker;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;

@Service
@Transactional
public class PetServiceImpl implements IPetService {
    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PettypeMapper pettypeMapper;
    @Autowired
    private IdWorker idWorker;

    @Override
    public List<Pet> findAllById(Integer id) {
        List<Pet>pets = petMapper.findAllById(id);
        return pets;
    }

    @Override
    public Pet findById(Long pId) {
        Pet pet = petMapper.findById(pId);
        return pet;
    }

    @Override
    public void editPet(String pName, Integer pAge, Integer pSex, Integer havepic, String picurl, Date pBirthday, Integer pType,Long pId) {
        petMapper.editPet(pName, pAge, pSex,havepic,picurl, pBirthday, pType,pId);
    }


    @Override
    public void addPet(Pet pet) {
        pet.setpId(idWorker.nextId());
        petMapper.addPet(pet);

    }

    @Override
    public void delPet(Long pId) {
        petMapper.delPet(pId);
    }

    //宠物类型
    @Override
    public List<Pettype> findAll() {
        List<Pettype> plist = pettypeMapper.finAll();
        return plist;
    }
}
